<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<html:html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title></title>
	<META http-equiv=Pragma content=no-cache>
	<META http-equiv=Cache-Control content=no-cache>
	<META http-equiv=Expires content=0>
	<link rel="stylesheet"
		href="<%=request.getContextPath()%>/resource/css/style.css"
		type="text/css">
	<script language="javascript" type="text/javascript"
		src="<%=request.getContextPath()%>/style/scripts/util.js"></script>
	<script language="javascript" type="text/javascript"
		src="<%=request.getContextPath()%>/resource/js/AdyhUtil.js"></script>
	<script language="javascript" type="text/javascript"
		src="<%=request.getContextPath()%>/resource/js/Validator.js"></script>		
	<script language="javascript" type="text/javascript"
		src="<%=request.getContextPath()%>/resource/calendar/DCDA_C03.js"></script>
	<script type="text/javascript"
		src="<%=request.getContextPath()%>/style/ext/adapter/ext/ext-base.js"></script>
	<script type="text/javascript"
		src="<%=request.getContextPath()%>/style/ext/ext-all.js"></script>		
<script type="text/javascript">
/**保存*/
function ShowAlert()
{ResetMe();
	var phasesCode = document.getElementById("phasesCode").value;
	var materialCode = document.getElementById("materialCode").value;
	var materialName = document.getElementById("materialName").value;
	var	quantity = document.getElementById("quantity").value;
	var objPrompt = document.getElementById("divPrompt");
    objPrompt.style.display = "block";
    objPrompt.innerHTML = "";
	if(phasesCode.length==0||materialCode==0||materialName==0||quantity==0
		||!check_naturalnumber(quantity)){
		if(phasesCode.length==0){
			objPrompt.innerHTML += "<li><bean:message key="F02.PhasesName"/> <bean:message key="adyh.error.isnull"/>";
			document.getElementById("phasesCode").className = "MyControlError";
		}
		if(materialCode.length==0){
			objPrompt.innerHTML += "<li><bean:message key="adyh.materialCode"/> <bean:message key="adyh.error.isnull"/>";
			document.getElementById("materialCode").className = "MyControlError";
		}
		if(materialName.length==0){
			objPrompt.innerHTML += "<li><bean:message key="adyh.materialName"/> <bean:message key="adyh.error.isnull"/>";
			document.getElementById("materialName").className = "MyControlError";
		}
		if(quantity.length==0){
			objPrompt.innerHTML += "<li><bean:message key="adyh.quantity"/> <bean:message key="adyh.error.isnull"/>";
			document.getElementById("quantity").className = "MyControlError";
		}
		if(!check_naturalnumber(quantity)){
			objPrompt.innerHTML += "<li><bean:message key="adyh.quantity"/> <bean:message key="adyh.error.number"/>";
			document.getElementById("quantity").className = "MyControlError";			
		}
	}else{
		var operationType = document.getElementById("operationType").value;
		operation(operationType);
	}
}
/**重置*/
function ResetMe()
{
   document.getElementById("phasesCode").className = "MySelect";
	document.getElementById("materialCode").className = "MyText";
	document.getElementById("materialName").className = "MyText";
	document.getElementById("quantity").className = "MyText";		
	var objPrompt = document.getElementById("divPrompt");
    objPrompt.style.display = "none";
	objPrompt.innerHTML = "";
}  
function getMessage() 
  {
	var errorMsg = document.forms[0].errorFlag.value;
	
	if ("" != errorMsg) {
		//**操作成功！*/
		if (errorMsg == 0) {
			alert("<bean:message key="common.alert1"/>");
		}
		//**操作失败！*/
		if (errorMsg == 1) {
			alert("<bean:message key="common.alert2"/>");
		}
		//**查询无结果！*/
		if (errorMsg == 2) {
			alert("<bean:message key="common.alert3"/>");
		}
		//**系统异常，请联系管理员！*/
		if (errorMsg == 3) {
			alert("<bean:message key="common.alert4"/>");
		}
		//document.forms[0].errorFlag.value = "";
	}
  }
/** 保存数据，返回booelan */
function JudgmentSample(h,rowid)
  {
	var quantity;
	var code = document.getElementById("code").value;
	var count;
	if(h>0){	
		quantity = document.forms[0].quantity[h].value;	
	}else{
		quantity = document.forms[0].quantity.value;	
	}
		 Ext.Ajax.request({
 	 url : 'F020204.do' , 
	 params : {operationType:'ajax',id:'update',code:code,rowId:rowid,quantity:quantity},
	 method: 'POST',
	 success: function ( result, request) {
		      var obj= Ext.decode(result.responseText) ;
			  var flag = obj.data.value1;
			  if(flag=="0"){					
				alert("<bean:message key="common.alert1"/>");
			  }else{
				alert("<bean:message key="common.alert2"/>");
			  }	
	},
	failure: function ( result, request) { 
				alert("<bean:message key="adyh.error.request"/>");
	} 
		});
  }
//刷新detailList  
function FiltDetailList()
  {  		      	      	
   		operation('refresh');
  }
//校验是否有返回值,为父页面调用  
function CheckEmpty()
  {  	  		
   		if(document.forms[0].errorFlag.value==""){
   			return true;
   		}else{
   			return false;
   		}
  }  
/*----------------------------------bengin---------------------------------*/  
//动态加载 
function comboBox(obj)
  {
  		var strValue = Jtrim(obj.value);   
		if(strValue==""){//检索条件为空时，不检索
			return ;
		}
  		
  		if(event.keyCode==38||event.keyCode==40||event.keyCode==13){
			keyEnter();
			return;
		}
  				
		var strId =  obj.name;
		  
		//回显的value1的字段名称
		var strCode = "";
		//回显的value2的字段名称
		var strName = "";
		//回显的value3的字段名称
		var strDes = "";
		//相应的div的名称

		var strObj = "rtnList";
		strTextName=strId		
		//在code处动态输入

				
		strCode = "materialCode";
		strName = "materialName";							
		strDes  = "description";
			
   		Ext.Ajax.request(
   		{
		url : 'F020202.do' , 
		params : {operationType:'ajax',id:'comboBox',code:strId,name:strValue},
		method: 'POST',
		success: function ( result, request) 
			{
			var listArray = new Array();
			var obj= Ext.decode(result.responseText) ;
			var objPrompt = document.getElementById(strObj);			
			objPrompt.style.display = "block";		
			objPrompt.innerHTML = "";
			initPosition(strObj);
			listArray = obj.data.list;
			var inn = "<table WIDTH=\"100%\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\" bgcolor=\"#FFFFFF\" id=\"sup\" class=\"ListBackground\">";
 	        for (i=0; i<listArray.length; i++){
				inn += "<tr height=\"20\" id=\"row"+(i)+"\"  onClick=\"javascript:showIn3('"+strObj+"','"+strCode+"','"+listArray[i][0]+"','"+strName+"','"+listArray[i][1]+"','"+strDes+"','"+listArray[i][2]+"')\">";
				inn += "<td>";
				inn += listArray[i][1];
				inn += "</td>";
				inn += "</tr>";
			}
			inn+="</table>";
			
			rownum=i;//获取动态加载的行数
			
			//若检索的结果是空，关闭div
			if(listArray.length==1&&listArray[0][0]==""&&listArray[0][1]==""){
				inn = "";
				objPrompt.style.display = "none";
			}
			
			objPrompt.innerHTML += inn;
			if(rownum>0&&inn!=""){
				document.getElementById("row0").focus();
			}
			FocusTableRow1("sup",0);//鼠标划过变色
			setPosition(strObj,strName);	//设置div的位置	
			//KeyCodeTableRow("sup",numsup);//设置当前焦点所在行的颜色

			},	
		failure: function ( result, request) { 
			alert("<bean:message key="adyh.error.request"/>");
			} 
		}
		);
  }

//初始化div的位置

  function initPosition(strObj){
	var objPrompt = document.getElementById(strObj);
	objPrompt.style.top=0;
	objPrompt.style.left=0;
  }
  
  //设置div的位置

  function setPosition(strObjPrompt,strObjText){
  	var objPrompt = document.getElementById(strObjPrompt);
	var objText = document.getElementById(strObjText);
	objPrompt.style.top = 20-(objPrompt.offsetTop-objText.offsetTop);
	objPrompt.style.left = objText.offsetLeft-20;
  }
  
  //设置div的位置

  function initColumn(){  				
  	document.getElementById("materialCode").value = "";
	document.getElementById("materialName").value = "";
  }
/*----------------------------------end---------------------------------*/
</script>		
</head>
<body onLoad="getMessage();CheckEmpty();">
	<html:form method="post" action="/pages/F02/F020204.do"
		enctype="multipart/form-data">
		<html:hidden property="language"/>
		<html:hidden property="operationType" />
		<html:hidden property="code" />
		<html:hidden property="id" />
		<html:hidden property="errorFlag" />		
		<!--Begin：表单主体区块-->
		<div id="divDlock" class="DivBlock">
			<div class="DivWrap">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td>
							<strong><bean:message key="F02.Bom" />
							</strong>
						</td>
					</tr>
				</table>
			</div>
			<div class="DivTail">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<TR>
						<TD ALIGN="right" NOWRAP WIDTH="12%">
							<!--工艺阶段-->
							<bean:message key="F02.PhasesName" />&nbsp;							
						</TD>
						<TD ALIGN="left" NOWRAP WIDTH="18%">
							<html:select property="phasesCode" styleClass="MySelect" onchange="FiltDetailList();">
								<html:option value=""></html:option>
								<html:optionsCollection property="phasesList" value="CODE"
									label="NAME" />
							</html:select>
							<span class="Need">*</span>
						</TD>
						<TD ALIGN="right" NOWRAP WIDTH="12%">
							<!--材料代码-->
							<bean:message key="adyh.materialCode" />&nbsp;						
						</TD>
						<TD ALIGN="left" NOWRAP WIDTH="18%">
							<html:text property="materialCode" styleClass="MyText" onkeyup="comboBox(this)" ondblclick="comboBox(this)" onblur="loseFocus('rtnList')" style="position:relative"/>
							<span class="Need">*</span>
						</TD>
						<TD ALIGN="right" NOWRAP WIDTH="12%">
							<!--材料名称-->
							<bean:message key="adyh.materialName" />&nbsp;							
						</TD>
						<TD ALIGN="left" NOWRAP WIDTH="18%">
							<html:text property="materialName" styleClass="MyText" onkeyup="comboBox(this)" ondblclick="comboBox(this)" onblur="loseFocus('rtnList')" style="position:relative" />
							<span class="Need">*</span>
						</TD>
						<TD ALIGN="left" NOWRAP WIDTH="10%">							
						</TD>
					</TR>
					<TR>						
						<TD ALIGN="right" NOWRAP WIDTH="12%">
							<!--描述-->
							<bean:message key="adyh.description" />&nbsp;							
						</TD>
						<TD ALIGN="left" NOWRAP colspan="3" WIDTH="*%">
							<html:text property="description" style="width:96%" readonly="true" styleClass="MyTextReadOnly" />							
						</TD>						
						<TD ALIGN="right" NOWRAP WIDTH="12%">
							<!--数量-->
							<bean:message key="adyh.quantity" />&nbsp;							
						</TD>
						<TD ALIGN="left" NOWRAP WIDTH="18%">							
							<html:text property="quantity" styleClass="MyText" />
							<span class="Need">*</span>													
						</TD>
						<TD ALIGN="left" NOWRAP WIDTH="10%">
							<input type="button" name="add" class="MyButton"
								onClick="ShowAlert();" value="<bean:message key="common.add"/>">							
						</TD>
					</TR>
				</table>				
			</div>
			<div class="DivPrompt" id="divPrompt" style="display:none">
			</div>
			<div class="DivTail">
				<table id="dytb" width="100%" cellpadding="1" cellspacing="1"
					border="0" rules="none"  class="ListBackground">
					<tbody id="tb1">
					<TR class="ListTitle" id="title">
						<TD ALIGN="center" NOWRAP WIDTH="10%">
							<!--工艺阶段-->
							<bean:message key="F02.PhasesName" />							
						</TD>
						<TD ALIGN="center" NOWRAP WIDTH="20%">
							<!--材料代码-->
							<bean:message key="adyh.materialCode" />							
						</TD>
						<TD ALIGN="center" NOWRAP WIDTH="25%">
							<!--材料名称-->
							<bean:message key="adyh.materialName" />							
						</TD>
						<TD ALIGN="center" NOWRAP WIDTH="25%">
							<!--描述-->
							<bean:message key="adyh.description" />							
						</TD>
						<TD ALIGN="center" NOWRAP WIDTH="10%">
							<!--数量-->
							<bean:message key="adyh.quantity" />							
						</TD>						
						<TD ALIGN="center" NOWRAP WIDTH="10%">
							<!--操作-->
							<bean:message key="common.operate" />							
						</TD>
					</TR>
					<%
					int i = 1;
					%>
					<logic:iterate id="rowp" name="F020204ActionForm" property="list">
						<tr class="ListRow1">
							<td nowrap align="center">
								<bean:write name="rowp" property="phasesName" />
							</td>
							<td nowrap align="center">
								<bean:write name="rowp" property="materialCode" />
							</td>
							<td nowrap align="center">
								<bean:write name="rowp" property="materialName" />
							</td>
							<td nowrap align="center">
								<bean:write name="rowp" property="description" />
							</td>
							<td nowrap align="center">
								<input name="quantity" type="text" style="text-align:right" class="MyText" size="10"
								 	value="<bean:write name="rowp" property="quantity" />"/>
							</td>																		
							<td nowrap align="center">
								<a
									href="javascript:JudgmentSample('<%=i++%>','<bean:write name="rowp" property="id"/>')"
									target="_self"><bean:message key="common.save"/></a>			
								<a
									href="javascript:deleteByCode('<bean:write name="rowp" property="id"/>')"
									target="_self"><bean:message key="common.delete"/></a>											
							</td>
						</tr>
					</logic:iterate>					
					</tbody>
				</table>
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td class="fieldset2">
							<bean:define id="actionFormName" value="F020204ActionForm" />
							<%@ include file="../../style/pagejsp/pageable.jsp"%>
						</td>
					</tr>
				</table>
			</div>		
		<!--End：查询列表-->																
		</div>
		<!--End：表单主体区块-->
		<div id="rtnList" style="display: black; position:relative; width:135"  onmouseleave="col(this);initColumn()">
		</div>					
	</html:form>
</body>
</html:html>
<script language="javascript" type="text/javascript">
InitForm();
FocusTableRow("tbList",1);
</script>
